<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button class="m-r10" @click="chaxun(1,bizhong)">今日</Button>
				<Button class="m-r10" @click="chaxun(2,bizhong)">近7天</Button>
				<Button class="m-r10" @click="chaxun(3,bizhong)">近30天</Button>
				<Button type="primary" @click="query">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累积转入积分:
								<span class="blue">{{ hzBlist.shiftNum }}</span>
							</td>
							<td>累积提币USDT:
								<span class="blue">{{ hzBlist.rollOutNum }}</span>
							</td>
							<td>累积销售产品:
								<span class="blue">{{ hzBlist.quantityPut }}</span>
							</td>
							<td>累积发放奖池:
								<span class="blue">{{ hzBlist.steadyPut }}</span>
							</td>
							<td>累积转入手续费:
								<span class="blue">{{ hzBlist.quantityPrincipalFee }}</span>
							</td>
							<td>累积提币手续费:
								<span class="blue">{{ hzBlist.quantityEarningFee }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns1" :data="btcList" ref="table" v-show="btc"></Table>
		<Page :total="dataCount" show-elevator :page-size="pageSize" show-total @on-change="changepage" v-show="fenye"></Page>
		<Page :total="dataCount1" show-elevator :page-size="pageSize1" show-total @on-change="changepage1" v-show="fenye1"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				btc: true,
				eth: false,
				fenye: true,
				fenye1: false,
				bizhong: '2',
				btcList: [], // btc数据
				ethList: [], // eth数据
				hzBlist: [], // BTC汇总数据
				hzElist: [], // ETH汇总数据
				huizong: [],
				startTime: '',
				endTime: '',
				falg: false,
				// 分页
				ajaxHistoryData: [],
				ajaxHistoryData1: [],
				// 初始化信息总条数
				dataCount: 0,
				dataCount1: 0,
				// 每页显示多少条
				pageSize: 20,
				pageSize1: 20,
				columns1: [{
						title: '日期',
						key: 'createTime',
						align: 'center',
						sortable: true,
						fixed: 'left',
						render: (h, params) => {
							return h('div', params.row.createTime.substring(0, 10))
						}
					},
					{
						title: '累积转入积分',
						align: 'center',
						key: 'shiftNum'
					},
					{
						title: '累积提币USDT',
						align: 'center',
						key: 'quantityAward'
					},
					{
						title: '累积销售产品',
						align: 'center',
						key: 'steadyAward'
					},
					{
						title: '累积发放奖池',
						align: 'center',
						key: 'quantityPut'
					},
					{
						title: '累积转入手续费',
						align: 'center',
						key: 'steadyPut'
					},
					{
						title: '累积提币手续费',
						align: 'center',
						key: 'quantityPrincipalFee'
					}
				]
			}
		},
		methods: {
			exportData() {
				this.$refs.table.exportCsv({
					filename: '财务统计BTC'
				})
				this.$refs.table1.exportCsv({
					filename: '财务统计ETH'
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			// 获取btc数据
			getBList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					currency: 2
				})
				this.axios
					.post('financial/statisticslist', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						if(res.data.code == 8008) {
							// console.log(res)
							this.btcList = res.data.data.data
							this.dataCount = this.btcList.length
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 获取eth数据
			getEList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					currency: 1
				})
				this.axios
					.post('financial/statisticslist', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						if(res.data.code == 8008) {
							// console.log(res)
							this.ethList = res.data.data.data
							this.dataCount1 = this.ethList.length
						}
					})
			},
			// 获取全部汇总
			getHuizong() {
				let token = localStorage.getItem('mytoken')
				this.axios
					.get('financial/collect', {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res);
						if(res.data.code == 8008) {
							this.hzBlist = res.data.data.BtcCollectVO
							this.hzElist = res.data.data.EthCollectVO
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// 查询
			query() {
				// console.log(this.bizhong)
				if(this.bizhong == 1) {
					this.btc = false
					this.eth = true
					this.fenye = false
					this.fenye1 = true
					setTimeout(() => {
						this.handleList()
					}, 500)
					if(this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0) {
						this.getEList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						currency: 1,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/statisticslist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								// console.log(res)
								this.ethList = res.data.data.data
								this.handleList()
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				} else if(this.bizhong == 2) {
					this.btc = true
					this.eth = false
					this.fenye = true
					this.fenye1 = false
					setTimeout(() => {
						this.handleListApproveHistory()
					}, 500)
					if(this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0) {
						this.getBList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						currency: 2,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/statisticslist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								// console.log(res)
								this.btcList = res.data.data.data
								this.handleListApproveHistory()
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				}
			},
			// 今日 7日 一个月 数据
			chaxun(id, currency) {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					typeId: id,
					currency: currency
				})
				this.axios
					.post('financial/statisticslist', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					})
					.then(res => {
						// console.log(res);
						if(res.data.code == 8008) {
							this.btcList = res.data.data.data
							this.handleListApproveHistory()
							this.ethList = res.data.data.data
							this.handleList()
							this.$Message.info(res.data.message)
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message)
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
			},
			// btc分页
			handleListApproveHistory() {
				// 保存取到的所有数据
				this.ajaxHistoryData = this.btcList
				this.dataCount = this.btcList.length
				// 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
				if(this.dataCount < this.pageSize) {
					this.btcList = this.ajaxHistoryData
				} else {
					this.btcList = this.ajaxHistoryData.slice(0, this.pageSize)
				}
			},
			changepage(index) {
				var _start = (index - 1) * this.pageSize
				var _end = index * this.pageSize
				this.btcList = this.ajaxHistoryData.slice(_start, _end)
			},
			// etc分页
			handleList() {
				// 保存取到的所有数据
				this.ajaxHistoryData1 = this.ethList
				this.dataCount1 = this.ethList.length
				// 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
				if(this.dataCount1 < this.pageSize1) {
					this.ethList = this.ajaxHistoryData1
				} else {
					this.ethList = this.ajaxHistoryData1.slice(0, this.pageSize)
				}
			},
			changepage1(index) {
				var _start1 = (index - 1) * this.pageSize1
				var _end1 = index * this.pageSize1
				this.ethList = this.ajaxHistoryData1.slice(_start1, _end1)
			}

		},
		created() {
			this.getBList()
			// setTimeout(() => {
			//   this.getEList();
			// },200)
			this.getHuizong()
			setTimeout(() => {
				this.handleListApproveHistory()
			}, 500)
		},
		mounted() {
			this.$Message.config({
				top: 250
			})
		}
	}
</script>